package com.f5.management.controller;

import com.f5.management.entity.Building;
import com.f5.management.service.BuildingService;
import com.f5.management.utils.PageResult;
import com.f5.management.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/building")
@CrossOrigin(origins = {"http://localhost:8080", "null"})
public class BuildingController {
    @Autowired
    private BuildingService buildingService;

    //添加信息
    @RequestMapping("/add")
    public ResponseResult<String> add(Building building) {

        return new ResponseResult<String>(buildingService.add(building));
    }

    //添加时查询名字是否存在
    @RequestMapping("/selectName")
    public ResponseResult<String> selectName(String name) {
        return new ResponseResult<String>(buildingService.selectName(name));
    }

    //通过名字查询Bid
    @RequestMapping("/findBidByName")
    public int findCidByName(String name) {

        return buildingService.findBidByName(name);
    }

    //更改信息
    @RequestMapping("/updateInfo")
    public ResponseResult<String> updateInfo(Building building) {

        return new ResponseResult<String>(buildingService.updateInfo(building));

    }

    //查询编号是否存在
    @RequestMapping("/selectNumber")
    public ResponseResult<String> selectNumber(String serialNumber) {
        return new ResponseResult<String>(buildingService.selectNumber(serialNumber));
    }

    //更改状态
    @RequestMapping("/updateStatus")
    public ResponseResult<String> updateStatus(int id, boolean status) {

        return new ResponseResult<String>(buildingService.updateStatus(id, status));

    }

    //删除信息
    @RequestMapping("/delInfo")
    public ResponseResult<String> delInfo(int id) {

        return new ResponseResult<String>(buildingService.delInfo(id));

    }

    //分页展示信息
    @RequestMapping("/findByPage")
    public PageResult<List<Building>> findByPage(int page, int size) {

        return buildingService.findByPage(page, size);
    }

    //id查询数据进行修改
    @RequestMapping("/findById")
    public ResponseResult<Building> findById(int id) {
        Building building = buildingService.findById(id);
        return new ResponseResult<Building>(true).setData(building);
    }

    //条件查询信息
    @RequestMapping("/findByCid")
    public PageResult<List<Building>> findByCid(int cid, String name, String serialNumber, int page) {
        //调用service方法查询数据
        PageResult<List<Building>> building = buildingService.findByCid(cid, name, serialNumber, page, 10);
        return building;
    }
}

















